package com.glsc.ngateway.opmanage.controller;

import com.glsc.ngateway.opmanage.service.UserService;
import com.glsc.ngateway.opmanage.service.other.DigitalKeyService;
import com.glsc.ngateway.common.api.common.enums.DictConstant;
import com.glsc.ngateway.common.api.common.ex.Result;
import com.glsc.ngateway.opmanage.service.other.TradeSeatFeesService;
import com.glsc.ngateway.opmanage.service.other.TradeSeatRentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: libj
 * @Date: 2021/10/20
 * @Desc: 作业信息管理
 */
@RestController
@RequestMapping("/api/jobcontrol")
@Api(value = "JobControlController", tags = {"作业信息管理管理接口"})
public class JobController {

    private static Logger logger = LoggerFactory.getLogger(JobController.class);

    @Value("${job_token}")
    String jobToken;

//    @Resource
//    private SystemLicenseExpireService systemLicenseExpireService;
    @Resource
    private UserService userService;

    @Resource
    private DigitalKeyService digitalKeyService;

//    @Resource
//    private EventImproveService eventImproveService;

    @Autowired
    private TradeSeatFeesService tradeSeatFeesService;

    @Autowired
    private TradeSeatRentService tradeSeatRentService;

    /**
     * 根据传入参数不同执行不同的任务
     *
     * @param jobType
     * @return
     */
    @GetMapping("/run")
    @ApiOperation(value = "执行", notes = "执行")
    public Result run(@ApiParam(value = "任务类型") @RequestParam(required = true) String jobType,
                      @RequestParam(required = true) String token) {
        String config = jobToken;
        if (config == null || !config.equals(token)) {
            logger.error("口令未配置或口令不正确");
            return Result.failData("口令未配置或口令不正确");
        }
        String returnString = "";
        try {
            logger.info("任务类型为" + jobType);
            switch (jobType) {
//                case DictConstant.JOB_NOTIFY_TIME_END_LICENSE:
//                    systemLicenseExpireService.timeEndNotify();
//                    break;
                case DictConstant.JOB_SYNC_OA_USER:
                    returnString = userService.updateUnLoginUser();
                    break;
                case DictConstant.JOB_DIGITAL_KEY_EXPIRE_DATE_REMIND:
                    returnString = digitalKeyService.remindExpire();
                    break;
                case DictConstant.DIGITAL_KEY_ALL_LIST:
                    returnString = digitalKeyService.remindLeaderDigitalKeyList();
                    break;
                case DictConstant.DIGITAL_KEY_UPDATE_DEPT:
                    returnString = digitalKeyService.updateDept(null);
                    break;
//                case DictConstant.NOTIFY_EVENT_IMPROVE_END:
//                    returnString = eventImproveService.notifyEventImproveEnd(null);
//                    break;
//                case DictConstant.READ_SH_TRADE_SEAT_EXCEL_INFO: 0 0 1 * * ? *
//                    returnString = tradeSeatFeesService.readShTreadSeatInfo();
//                    break;
//                case DictConstant.READ_SZ_TRADE_SEAT_EXCEL_INFO: 0 0 0 * * ? *
//                    returnString = tradeSeatFeesService.readSzTreadSeatInfo();
//                    break;
//                case DictConstant.UPDATE_TRADE_SEAT_INFO_DATE_LINE: 0 0 3 * * ? *
//                    returnString = tradeSeatFeesService.updateFeesByDateLine();
//                    break;
//                case DictConstant.UPDATE_TRADE_SEAT_RENT_BY_HISTORY:
//                    returnString = tradeSeatRentService.updateTradeSeatRentByHistory();
//                    break;
                default:
                    return Result.failData("未匹配上任务");
            }
        } catch (Exception e) {
            logger.error("杜芬调用异常：",e);
            return Result.failData(e.getMessage() + returnString);
        }

        return Result.successData("成功" + returnString);
    }
}
